package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chainyoung.common.jsoup.interfaces.Text;
import com.chainyoung.common.utils.ConvertUtils;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.entity.BankItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WordsAdapter extends BaseAdapter {

    private List<String> wordsList;
    private Context mContext;
    private boolean isFromSelect;

    private int selectIndex=-1;

    public WordsAdapter(Context context, List<String> words) {
        wordsList = words;
        mContext = context;
    }

    public WordsAdapter(Context context, List<String> words,boolean isFromSelect) {
        wordsList = words;
        mContext = context;
        this.isFromSelect=isFromSelect;
    }

    @Override
    public int getCount() {
        return wordsList.size();
    }

    @Override
    public Object getItem(int position) {
        return wordsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_words_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ConvertUtils.dp2px(mContext,40)));
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        String item = wordsList.get(position);
        viewHolder.tvName.setText(item);
        viewHolder.tvIndex.setText(position + 1 + "");
        if (selectIndex==position){
            viewHolder.rlWord.setBackgroundResource(R.drawable.shape_words_bg_selected);
            viewHolder.tvIndex.setTextColor(ContextCompat.getColor(mContext,R.color.white));
            viewHolder.tvName.setTextColor(ContextCompat.getColor(mContext,R.color.white));
        }else {
            viewHolder.rlWord.setBackgroundResource(R.drawable.shape_words_bg);
            viewHolder.tvIndex.setTextColor(ContextCompat.getColor(mContext,R.color._7e8da6));
            viewHolder.tvName.setTextColor(ContextCompat.getColor(mContext,R.color._061c69));
        }



        return convertView;
    }


    static class ViewHolder {

        @BindView(R2.id.tv_word)
        TextView tvName;
        @BindView(R2.id.tv_index)
        TextView tvIndex;
        @BindView(R2.id.rl_word)
        RelativeLayout rlWord;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
    }


}
